package com.ruoyi.user.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.manage.domain.GoodsShelves;
import com.ruoyi.manage.domain.User;
import com.ruoyi.manage.domain.vo.GoodsShelvesVo;
import com.ruoyi.manage.service.IGoodsShelvesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author ZhangZhongGen
 */
@RestController
@RequestMapping("/userWeixin/vm")
public class UserVmController extends BaseController {

    @Autowired
    private IGoodsShelvesService goodsShelvesService;

    /**
     * 通过设备id查询货架信息
     * @param goodsShelves
     * @return
     */
    @GetMapping("/voList")
    public TableDataInfo voList(GoodsShelves goodsShelves)
    {
        List<GoodsShelvesVo> list = goodsShelvesService.selectGoodsShelvesVoList(goodsShelves);
        return getDataTable(list);
    }

    /**
     * 获取给用户-在该货架上-待取货的物品列表
     * @param goodsShelves
     * @return
     */
    @GetMapping("/list/{type}")//0-待取货，1-待入库
    public TableDataInfo listPickup(@PathVariable("type") Integer type, GoodsShelves goodsShelves)
    {
        List<GoodsShelvesVo> list = goodsShelvesService.selectGoodsShelvesVoListByPickup(goodsShelves.getDeviceNumber(),getUser().getId(),type);
        return getDataTable(list);
    }

    public User getUser(){
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        User principal = (User) authentication.getPrincipal();
        return principal;
    }
}
